package jwlee.testthread;

public class MyThread extends Thread {
	public MyThread() {
		Runtime.getRuntime().addShutdownHook(new Thread() {
			public void run() {
				System.out.println("virtual-machine shutdown hook...");
			}
		});
	}

	public void run() {
		System.out.println("running...");
	}

	public static void main(String[] args) {
		MyThread mt = new MyThread() {
			public void run() {
				try {
					for (int i = 0; i < 10; i++) {
						System.out.println(i);
						if (i == 5)
							throw new InterruptedException();
						Thread.sleep(100);
					}
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		};
		mt.start();
		// mt.start();//can't start twice
	}

}
